package com.wuyou.securitydemo.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.security.core.SpringSecurityCoreVersion;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;

/**
 * TokenVO
 *
 * @Date 2025/4/11 10:48
 * @Author 无忧
 */
@Data
public class TokenVO implements Serializable {

    private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;


    private String token;

    private String tokenType;

    private LocalDateTime expire;

    private Date expiration;

    private String refreshToken;

    private Long userId;

    private String userName;

    private String displayName;

    private Map<String, Object> additional;




    @JsonIgnore
    public Boolean isActive() {
        return null != this.expire && !LocalDateTime.now().isAfter(this.expire);
    }

    public int getExpiresIn() {
        return this.expiration != null ? Long.valueOf((this.expiration.getTime() - System.currentTimeMillis()) / 1000L).intValue() : 0;
    }
}
